package org.lanqiao.api.cart;

import java.io.IOException;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.lanqiao.common.Constants;
import org.lanqiao.common.JsonResult;
import org.lanqiao.common.JsonResultWriter;
import org.lanqiao.service.CartServiceImpl;

/**
 * 删除购物车的接口
 * @author dzp
 *
 */
@WebServlet("/api/cart/delete")
public class DeleteCartServlet extends HttpServlet {

	protected void service(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		//传入参数，传入购物车编号carId和用户编号；购物车编号用来删除，用户编号用来执行查询购物车
	    String id = request.getParameter("CarId");
	    String userId = request.getParameter("UserId");
		JsonResult result=null;
		
		CartServiceImpl removeCartService = new CartServiceImpl();		
	    List  list  = removeCartService.delete(id,userId);
//	    System.out.println(list.size());
		try {
			if(list.size()>0){				
				result = new JsonResult("删除成功",Constants.STATUS_SUCCESS,list);
			}else {				
				result=new JsonResult( "删除购物车失败",Constants.STATUS_UNFOUND);
			}
		} catch (Exception e) {			
			result=new JsonResult("删除异常",Constants.STATUS_FAILURE);
		}
		
		JsonResultWriter.writer(response, result);
	}

}
